package com.deng.maintenance.employee.view
{
	import com.deng.common.vo.EmployeeVo;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.controls.CheckBox;
	import mx.events.FlexEvent;
	import mx.resources.ResourceManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;

	public class EmployeeInuseCB extends CheckBox
	{
		private var selVo:EmployeeVo;
		public function EmployeeInuseCB()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,upEvt);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			super();
		}
		private function upEvt(event:MouseEvent):void{			
			var ro:RemoteObject = new RemoteObject();
			ro.destination = "EmployeeImpl";			
			ro.addEventListener(FaultEvent.FAULT,flt);
			ro.addEventListener(ResultEvent.RESULT,updateRst);
			if(this.selected){//之前选中的，后面要删除
				ro.setEmployeeInuse(selVo,0);
				selVo.in_use = 0;
			}else{//之前没选中，后面要增加
				ro.setEmployeeInuse(selVo,1);
				selVo.in_use = 1;	
			}			
		}
		private function updateRst(evt:ResultEvent):void{
			Alert.show(ResourceManager.getInstance().getString("lang", "update_success"));
//			var rtEvt:ReturnEvent=new ReturnEvent(ReturnEvent.loadDispenseManagerList);
//			rtEvt.dispatch();
		}
		private function flt(evt:FaultEvent):void{
			Alert.show(evt.fault.getStackTrace());
		}
		private function showHandler(evt:FlexEvent):void{
			selVo = this.data as EmployeeVo;
			if(selVo.in_use == 1){
				this.selected = true;
			}else{
				this.selected = false;
			}			
		}
	}
}